#  Copyright (c) General. 2022-2025. All rights reserved.
#  @file     : TestRegexHelper.py
#  @time     : 11:14:42
#  @date     : 2025/10/16
#  @mail     : 9727005@qq.com
#  @creator  : ShanDong Xiedali
#  @objective: Less is more. Simple is best!

import pytest
from BasicLibrary.data.regexHelper import RegexHelper


class TestRegexHelper:

    def test_determine_is_whole_matched_success(self):
        whole = "hello"
        pattern = r"hello"
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is True

    def test_determine_is_whole_matched_failure(self):
        whole = "hello world"
        pattern = r"hello"
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is False

    def test_determine_is_whole_matched_with_regex_success(self):
        whole = "123"
        pattern = r"\d+"
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is True

    def test_determine_is_whole_matched_with_regex_failure(self):
        whole = "abc123"
        pattern = r"\d+"
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is False

    def test_determine_is_whole_matched_with_empty_string(self):
        whole = ""
        pattern = r""
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is True

    def test_determine_is_whole_matched_with_empty_pattern(self):
        whole = "hello"
        pattern = r""
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is False

    def test_determine_is_whole_matched_with_special_characters_success(self):
        whole = "!@#"
        pattern = r"[!@#]+"
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is True

    def test_determine_is_whole_matched_with_special_characters_failure(self):
        whole = "!@#abc"
        pattern = r"[!@#]+"
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is False

    def test_determine_is_whole_matched_with_escaped_characters(self):
        whole = "hello.world"
        pattern = r"hello\.world"
        assert RegexHelper.determine_is_whole_matched(whole, pattern) is True


    def test_get_matched_items(self):
        whole = "I am in overseas(+01),and I love Qingdao(0532)!"
        pattern = r"\d+"

        actual = RegexHelper.get_matched_items(whole, pattern)
        expected = ['01', '0532']
        assert actual == expected

        pattern = r"^\d+"
        actual = RegexHelper.get_matched_items(whole, pattern)
        expected = []
        assert actual == expected


    def test_determine_is_matched(self):
        whole = "I am in Tengzhou(0632),and I love Qingdao(0532)!"
        pattern = r"^\d+"
        actual = RegexHelper.determine_is_matched(whole, pattern)
        expected = False
        assert actual == expected


    def test_replace(self):
        text = '今天是：11/28/2018'
        actual = RegexHelper.replace(text, r"(\d{2})/(\d{2})/(\d{4})", r"\3年\1月\2日")
        expected = '今天是：2018年11月28日'
        assert actual == expected


    def test_keep_prototypical(self):
        text = "(xx).png.txt"
        actual = RegexHelper.keep_prototypical(text)
        expected = r"\(xx\)\.png\.txt"
        assert actual == expected
